package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.HingeInstallation;
import com.ruoyi.system.mapper.HingeInstallationMapper;
import com.ruoyi.system.service.HingeInstallationService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 关键装置和重点部位(HingeInstallation)表服务实现类
 *
 * @author makejava
 * @since 2023-03-20 17:43:00
 */
@Service("hingeInstallationService")
public class HingeInstallationServiceImpl implements HingeInstallationService {
    @Resource
    private HingeInstallationMapper hingeInstallationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public HingeInstallation queryById(Integer id) {
        return this.hingeInstallationDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param hingeInstallation 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<HingeInstallation> queryByPage(HingeInstallation hingeInstallation, PageRequest pageRequest) {
        long total = this.hingeInstallationDao.count(hingeInstallation);
        return new PageImpl<>(this.hingeInstallationDao.queryAllByLimit(hingeInstallation, pageRequest), pageRequest, total);
    }

    @Override
    public List<HingeInstallation> queryAll(HingeInstallation hingeInstallation) {
        return hingeInstallationDao.queryAll(hingeInstallation);
    }

    /**
     * 新增数据
     *
     * @param hingeInstallation 实例对象
     * @return 实例对象
     */
    @Override
    public HingeInstallation insert(HingeInstallation hingeInstallation) {
        this.hingeInstallationDao.insert(hingeInstallation);
        return hingeInstallation;
    }

    /**
     * 修改数据
     *
     * @param hingeInstallation 实例对象
     * @return 实例对象
     */
    @Override
    public HingeInstallation update(HingeInstallation hingeInstallation) {
        this.hingeInstallationDao.update(hingeInstallation);
        return this.queryById(hingeInstallation.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.hingeInstallationDao.deleteById(id) > 0;
    }
}
